package com.myapp.mobilesafe.activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.myapp.mobilesafe.utils.SmsUtils;

import java.io.File;

public class AdvanceToolsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_advance_tools);
    }

    public void addressQuery(View view) {
        startActivity(new Intent(this,AddressQueryActivity.class));
    }

    public void smsBackup(View view) {
        if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
            final ProgressDialog dialog = new ProgressDialog(this);
            dialog.setMessage("正在备份短信...");
            dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);// 水平方向进度条,可以展示进度
            dialog.show();
            new Thread(){
                @Override
                public void run() {
                    File file = new File(Environment.getExternalStorageDirectory()
                            .getAbsolutePath()+"/sms_backup.xml");
                    SmsUtils.smsBackup(getApplicationContext(), file, new SmsUtils.SmsCallback() {
                        @Override
                        public void preSmsBackup(int count) {
                            dialog.setMax(count);
                        }
                        @Override
                        public void onSmsBackup(int progress) {
                            dialog.setProgress(progress);
                        }
                    });
                    dialog.dismiss();
                }
            }.start();

        }else {
            Toast.makeText(this,"请检测SD卡是否正常！！",Toast.LENGTH_SHORT).show();
        }

    }

    public void commonNumber(View view) {
        startActivity(new Intent(this, CommonNumberActivity.class));
    }

    public void appLock(View view) {
        startActivity(new Intent(this, AppLockActivity.class));
    }
}
